package io.renren.modules.heartself.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.heartself.dao.HeartStationDao;
import io.renren.modules.heartself.entity.HeartStationEntity;
import io.renren.modules.heartself.service.HeartStationService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("heartStationService")
public class HeartStationServiceImpl extends ServiceImpl<HeartStationDao, HeartStationEntity> implements HeartStationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String stationName = (String) params.get("stationName");
        Long userId = Long.parseLong(params.get("userId").toString());
        IPage<HeartStationEntity> page = this.page(
                new Query<HeartStationEntity>().getPage(params),
                new QueryWrapper<HeartStationEntity>().like(StringUtils.isNotBlank(stationName), "station_name", stationName)
                        .eq(userId != null, "user_id", userId)
        );

        return new PageUtils(page);
    }

}